//
//  BFNewFeatureController.m
//  beifang
//
//  Created by Apple on 17/4/14.
//  Copyright © 2017年 郭凯. All rights reserved.
//

#import "BFNewFeatureController.h"
#import "BFTabBarController.h"

@interface BFNewFeatureController ()<UICollectionViewDataSource>
@property(nonatomic,strong)UICollectionView *collectionView;
@end

@implementation BFNewFeatureController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
   
    UICollectionViewFlowLayout *flowlay = [[UICollectionViewFlowLayout alloc]init];
    flowlay.itemSize = [UIScreen mainScreen].bounds.size;
    flowlay.minimumLineSpacing = 0;
    flowlay.minimumInteritemSpacing = 0;
    flowlay.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionView.collectionViewLayout = flowlay;
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowlay];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.dataSource = self;
    collectionView.pagingEnabled = YES;
    collectionView.bounces = NO;
    collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView = collectionView;
    [self.view addSubview: collectionView];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:cell.bounds];
    NSString *name = [NSString stringWithFormat:@"new_feature_%ld-568h",indexPath.row+1];
    imageView.image = [UIImage imageNamed:name];
    [cell.contentView addSubview:imageView];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundColor:[UIColor orangeColor]];
    [btn setTitle:@"点击进入" forState:UIControlStateNormal];
    CGFloat btnWidth = 100;
    btn.frame  = CGRectMake((cell.bounds.size.width-btnWidth)*0.5, cell.bounds.size.height-100, btnWidth, 40);
    [btn addTarget:self action:@selector(goHome:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:btn];
    cell.backgroundColor = indexPath.row%2 ? [UIColor redColor] : [UIColor yellowColor];
    btn.hidden = indexPath.row==3 ? NO :YES;
    return cell;
}

// 进入主页
-(void)goHome:(UIButton *)btn{
    NSDictionary *infor = [[NSBundle mainBundle]infoDictionary];
    NSString *version = infor[@"CFBundleShortVersionString"];
    NSLog(@"infor=%@ version=%@",infor,version);
    [[NSUserDefaults standardUserDefaults]setValue:version forKey:@"appVersion"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    [UIApplication sharedApplication].keyWindow.rootViewController = [[BFTabBarController alloc]init];
}


@end
